using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using OVS.BusinessObjects;

namespace OVS.DAL
{
	public partial class CameraImage_HaarDAO
	{
		public CameraImage_HaarDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<CameraImage_Haar> GetCameraImage_Haars()
		{
			try
			{
				List<CameraImage_Haar> lstCameraImage_Haars = new List<CameraImage_Haar>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [Camera_came_id],[Image_Haar_imha_id] FROM [CameraImage_Haar]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					CameraImage_Haar oCameraImage_Haar = new CameraImage_Haar();
					oCameraImage_Haar.Camera_came_id = Convert.ToInt32(oDbDataReader["Camera_came_id"]);
					oCameraImage_Haar.Image_Haar_imha_id = Convert.ToInt32(oDbDataReader["Image_Haar_imha_id"]);
					lstCameraImage_Haars.Add(oCameraImage_Haar);
				}
				oDbDataReader.Close();
				return lstCameraImage_Haars;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public CameraImage_Haar GetCameraImage_Haar(int Camera_came_id,int Image_Haar_imha_id)
		{
			try
			{
				CameraImage_Haar oCameraImage_Haar = new CameraImage_Haar();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [Camera_came_id],[Image_Haar_imha_id] FROM [CameraImage_Haar] WHERE [Camera_came_id]=@Camera_came_id AND [Image_Haar_imha_id]=@Image_Haar_imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Camera_came_id",DbType.Int32,Camera_came_id));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Image_Haar_imha_id",DbType.Int32,Image_Haar_imha_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oCameraImage_Haar.Camera_came_id = Convert.ToInt32(oDbDataReader["Camera_came_id"]);
					oCameraImage_Haar.Image_Haar_imha_id = Convert.ToInt32(oDbDataReader["Image_Haar_imha_id"]);
				}
				oDbDataReader.Close();
				return oCameraImage_Haar;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddCameraImage_Haar(CameraImage_Haar oCameraImage_Haar)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [CameraImage_Haar]()VALUES()",CommandType.Text);

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveCameraImage_Haar(CameraImage_Haar oCameraImage_Haar)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [CameraImage_Haar] WHERE [Camera_came_id]=@Camera_came_id AND [Image_Haar_imha_id]=@Image_Haar_imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Camera_came_id",DbType.Int32,oCameraImage_Haar.Camera_came_id));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Image_Haar_imha_id",DbType.Int32,oCameraImage_Haar.Image_Haar_imha_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveCameraImage_Haar(int Camera_came_id,int Image_Haar_imha_id)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [CameraImage_Haar] WHERE [Camera_came_id]=@Camera_came_id AND [Image_Haar_imha_id]=@Image_Haar_imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Camera_came_id",DbType.Int32,Camera_came_id));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Image_Haar_imha_id",DbType.Int32,Image_Haar_imha_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public List<CameraImage_Haar> GetCameraImage_HaarsOfCamera(int Camera_came_id)
		{
			try
			{
				List<CameraImage_Haar> lstCameraImage_Haars = new List<CameraImage_Haar>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [Camera_came_id],[Image_Haar_imha_id] FROM [CameraImage_Haar] WHERE [Camera_came_id]=@Camera_came_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Camera_came_id",DbType.Int32,Camera_came_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					CameraImage_Haar oCameraImage_Haar = new CameraImage_Haar();
					oCameraImage_Haar.Camera_came_id = Convert.ToInt32(oDbDataReader["Camera_came_id"]);
					oCameraImage_Haar.Image_Haar_imha_id = Convert.ToInt32(oDbDataReader["Image_Haar_imha_id"]);
					lstCameraImage_Haars.Add(oCameraImage_Haar);
				}
				oDbDataReader.Close();
				return lstCameraImage_Haars;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Camera GetCameraOfCameraImage_Haar(int came_id)
		{
			try
			{
				Camera oCamera = new Camera();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [came_id],[came_loc],[came_url],[came_desc],[came_nom],[came_use] FROM [Camera] WHERE [came_id]=@came_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@came_id",DbType.Int32,came_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oCamera.came_id = Convert.ToInt32(oDbDataReader["came_id"]);
					oCamera.came_loc = Convert.ToString(oDbDataReader["came_loc"]);
					oCamera.came_url = Convert.ToString(oDbDataReader["came_url"]);

					if(oDbDataReader["came_desc"] != DBNull.Value)
						oCamera.came_desc = Convert.ToString(oDbDataReader["came_desc"]);

					if(oDbDataReader["came_nom"] != DBNull.Value)
						oCamera.came_nom = Convert.ToString(oDbDataReader["came_nom"]);

					if(oDbDataReader["came_use"] != DBNull.Value)
						oCamera.came_use = Convert.ToBoolean(oDbDataReader["came_use"]);
				}
				oDbDataReader.Close();
				return oCamera;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public List<CameraImage_Haar> GetCameraImage_HaarsOfImage_Haar(int Image_Haar_imha_id)
		{
			try
			{
				List<CameraImage_Haar> lstCameraImage_Haars = new List<CameraImage_Haar>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [Camera_came_id],[Image_Haar_imha_id] FROM [CameraImage_Haar] WHERE [Image_Haar_imha_id]=@Image_Haar_imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Image_Haar_imha_id",DbType.Int32,Image_Haar_imha_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					CameraImage_Haar oCameraImage_Haar = new CameraImage_Haar();
					oCameraImage_Haar.Camera_came_id = Convert.ToInt32(oDbDataReader["Camera_came_id"]);
					oCameraImage_Haar.Image_Haar_imha_id = Convert.ToInt32(oDbDataReader["Image_Haar_imha_id"]);
					lstCameraImage_Haars.Add(oCameraImage_Haar);
				}
				oDbDataReader.Close();
				return lstCameraImage_Haars;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Image_Haar GetImage_HaarOfCameraImage_Haar(int imha_id)
		{
			try
			{
				Image_Haar oImage_Haar = new Image_Haar();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [imha_id],[imha_fn],[imha_label],[imha_height],[imha_width],[imha_desc],[imha_scaleFactor],[imha_minNeighbors] FROM [Image_Haar] WHERE [imha_id]=@imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_id",DbType.Int32,imha_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oImage_Haar.imha_id = Convert.ToInt32(oDbDataReader["imha_id"]);
					oImage_Haar.imha_fn = Convert.ToString(oDbDataReader["imha_fn"]);

					if(oDbDataReader["imha_label"] != DBNull.Value)
						oImage_Haar.imha_label = Convert.ToString(oDbDataReader["imha_label"]);

					if(oDbDataReader["imha_height"] != DBNull.Value)
						oImage_Haar.imha_height = Convert.ToInt32(oDbDataReader["imha_height"]);

					if(oDbDataReader["imha_width"] != DBNull.Value)
						oImage_Haar.imha_width = Convert.ToInt32(oDbDataReader["imha_width"]);

					if(oDbDataReader["imha_desc"] != DBNull.Value)
						oImage_Haar.imha_desc = Convert.ToString(oDbDataReader["imha_desc"]);

					if(oDbDataReader["imha_scaleFactor"] != DBNull.Value)
						oImage_Haar.imha_scaleFactor = Convert.ToDouble(oDbDataReader["imha_scaleFactor"]);

					if(oDbDataReader["imha_minNeighbors"] != DBNull.Value)
						oImage_Haar.imha_minNeighbors = Convert.ToDouble(oDbDataReader["imha_minNeighbors"]);
				}
				oDbDataReader.Close();
				return oImage_Haar;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
